package com.test.myserver;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server1 {

    private ServerSocket server;

    /**
     * 启动服务器
     * 
     * @author 刘山禾 2016年12月14日 新建
     */
    public void start() {
        try {
            server = new ServerSocket(8666);
            this.receive();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void receive() {
        try {
            Socket client = server.accept();
            StringBuilder sb = new StringBuilder();
            String msg = null;// 保存客户端requestbody信息
            BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));//获取端口输入的数据
            while ((msg = br.readLine()).length() > 0) {//读取输入的数据
                sb.append(msg);
                sb.append("\r\n");
            }
            System.out.println(sb.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        Server1 server1 = new Server1();
        server1.start();
    }
}
